package org.sixtynine.stock.service.file;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.sixtynine.stock.Constants.CommonData;
import org.sixtynine.stock.entity.BaseEntity;
import org.sixtynine.stock.entity.Company;
import org.sixtynine.stock.entity.Sector;
import org.sixtynine.stock.entity.SubSector;
import org.sixtynine.stock.service.content.DataManagerService;

/**
 * abstract class for the share and sector data processors
 * 
 * @author Thilanka
 *
 */
public abstract class CompanyDataListProcessor extends ExcelProcessor {

	public Map<String, Company> companyMap;
	public Map<String, Sector> sectorMap;
	public Map<String, SubSector> subSectorMap;

	public void init() {
		List<BaseEntity> companyList = DataManagerService
				.getData(CommonData.COMPANY.toString());

		List<BaseEntity> sectorList = DataManagerService
				.getData(CommonData.SECTOR.toString());

		List<BaseEntity> subSectorList = DataManagerService
				.getData(CommonData.SUB_SECTOR.toString());

		sectorMap = new HashMap<String, Sector>();
		if (sectorList != null) {
			for (BaseEntity baseEntity : sectorList) {
				Sector sector = (Sector) baseEntity;
				sectorMap.put(sector.getCode(), sector);
			}
		}

		subSectorMap = new HashMap<String, SubSector>();
		if (subSectorList != null) {
			for (BaseEntity baseEntity : subSectorList) {
				SubSector subSector = (SubSector) baseEntity;
				subSectorMap.put(subSector.getCode(), subSector);
			}
		}

		companyMap = new HashMap<String, Company>();
		if (companyList != null) {
			for (BaseEntity baseEntity : companyList) {
				Company company = (Company) baseEntity;

				companyMap.put(company.getCode(), company);
			}
		}
	}

}
